home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolfedit2 2.0.4 source.sit / WolfEdit2 2.0.4 Source / UEditDoors.p < prev    next >
Text File  |  1995-11-04  |  4KB  |  181 lines

  1. unit UEditDoors;
  2.  
  3. interface
  4.     uses
  5.         UWolfDoc;
  6.  
  7.     procedure EditDoors (mapList: TMapListDoc);
  8.  
  9. implementation
  10.     uses
  11.         UEditArt, ULZSS;
  12.  
  13.     const
  14.  
  15.         doorEditDlogID = 132;
  16.         shadeItem = 5;
  17.         mirrorItem = 6;
  18.  
  19.         doorSideObjectCode = $FE;
  20.  
  21.     type
  22.  
  23.         TDoorImagePalette = object(TImagePalette)
  24.                 procedure IDoorImagePalette;
  25.                 procedure DrawImage (itemNo: integer; r: Rect);
  26.                 override;
  27.             end;
  28.  
  29.         TDoorEditDialog = object(TArtEditDialog)
  30.                 procedure IDoorEditDialog (itsMapList: TMapListDoc);
  31.                 procedure UninstallArt;
  32.                 override;
  33.                 procedure InstallArt;
  34.                 override;
  35.                 function ArtImageType: CustomImageType;
  36.                 override;
  37.                 function ArtImageCode: integer;
  38.                 override;
  39.                 procedure ChangeImage (gworld: GWorldPtr; isThumbnail: boolean);
  40.                 override;
  41.             end;
  42.  
  43.     function DoorObjectCode (itemNo: integer): integer;
  44.     begin
  45.         if itemNo < 4 then
  46.             DoorObjectCode := $5A + 2 * itemNo
  47.         else
  48.             DoorObjectCode := doorSideObjectCode;
  49.     end;
  50.  
  51.     function DoorImageCode (itemNo: integer): integer;
  52.         var
  53.             code: integer;
  54.     begin
  55.         code := DoorObjectCode(itemNo);
  56.         if itemNo < 4 then
  57.             code := code + 1;
  58.         DoorImageCode := code;
  59.     end;
  60.  
  61.  
  62.     procedure TDoorImagePalette.IDoorImagePalette;
  63.     begin
  64.         IImagePalette(5, 5);
  65.         fDialog := nil;
  66.     end;
  67.  
  68.     procedure TDoorImagePalette.DrawImage (itemNo: integer; r: Rect);
  69.     begin
  70.         fDialog.fMapList.PlotObject(DoorImageCode(itemNo), 0, r);
  71.     end;
  72.  
  73.     procedure TDoorEditDialog.IDoorEditDialog (itsMapList: TMapListDoc);
  74.         var
  75.             palette: TDoorImagePalette;
  76.     begin
  77.         new(palette);
  78.         palette.IDoorImagePalette;
  79.         IArtEditDialog(doorEditDlogID, palette, itsMapList, true);
  80.         palette.fDialog := self;
  81.     end;
  82.  
  83.     procedure TDoorEditDialog.UninstallArt;
  84.         var
  85.             wal: WallArtListHandle;
  86.  
  87.         procedure Uninstall (var this: WallArtListEntry);
  88.         begin
  89.             if fArtView.fChanged then begin
  90.                     if this.art <> nil then
  91.                         DisposHandle(this.art);
  92.                     this.art := fArtView.ExtractWall;
  93.                     fMapList.Changed;
  94.                     fArtView.fChanged := false;
  95.                 end;
  96.             UninstallFlag(this.darkFlag, shadeItem);
  97.             UninstallFlag(this.mirrorFlag, mirrorItem);
  98.         end;
  99.  
  100.     begin {TDoorEditDialog.UninstallDoor}
  101.         if fCurrentArt >= 0 then begin
  102.                 wal := fMapList.GetWallArtList;
  103.                 HLock(Handle(wal));
  104.                 Uninstall(wal^^[59 + fCurrentArt]);
  105.                 HUnlock(Handle(wal));
  106.             end;
  107.     end;
  108.  
  109.     procedure TDoorEditDialog.InstallArt;
  110.  
  111.         procedure Install (this: WallArtListEntry);
  112.         begin
  113.             fArtView.InstallWall(this.art);
  114.             InstallFlag(this.darkFlag, shadeItem);
  115.             InstallFlag(this.mirrorFlag, mirrorItem);
  116.         end;
  117.  
  118.     begin {TDoorEditDialog.InstallArt}
  119.         if fCurrentArt >= 0 then
  120.             Install(fMapList.GetWallArtList^^[59 + fCurrentArt]);
  121.     end;
  122.  
  123.     function TDoorEditDialog.ArtImageType: CustomImageType;
  124.     begin
  125.         ArtImageType := objectImage;
  126.     end;
  127.  
  128.     function TDoorEditDialog.ArtImageCode: integer;
  129.     begin
  130.         ArtImageCode := DoorImageCode(fCurrentArt);
  131.     end;
  132.  
  133.     procedure TDoorEditDialog.ChangeImage (gworld: GWorldPtr; isThumbnail: boolean);
  134.         var
  135.             buffer: packed array[0..127, 0..127] of 0..255;
  136.             pixels: Ptr;
  137.             width, height, bytes: longint;
  138.             code: integer;
  139.             shrink: boolean;
  140.     begin
  141.         code := ArtImageCode;
  142.         if gworld <> nil then begin
  143.                 pixels := GetPixBaseAddr(GetGWorldPixMap(gworld));
  144.                 width := gworld^.portRect.right;
  145.                 height := gworld^.portRect.bottom;
  146.                 bytes := width * height;
  147.                 shrink := (not isThumbnail) and (fCurrentArt < 4);
  148.                 ChangeDoorImage(code, gworld, shrink);
  149.                 if fCurrentArt < 4 then begin
  150.                         BlockMove(pixels, @buffer, bytes);
  151.                         TransposePixels(@buffer, pixels, width, height);
  152.                         ChangeDoorImage(code - 1, gworld, shrink);
  153.                         BlockMove(@buffer, pixels, bytes);
  154.                     end;
  155.             end
  156.         else begin
  157.                 ChangeDoorImage(code + 1, nil, false);
  158.                 ChangeDoorImage(code, nil, false);
  159.             end;
  160.     end;
  161.  
  162.     procedure EditDoors (mapList: TMapListDoc);
  163.         var
  164.             dlog: TDoorEditDialog;
  165.  
  166.         procedure CheckWindow (win: TWindow);
  167.         begin
  168.             if member(win, TDoorEditDialog) then begin
  169.                     win.Select;
  170.                     exit(EditDoors);
  171.                 end;
  172.         end;
  173.  
  174.     begin
  175.         mapList.EachWindowDo(CheckWindow);
  176.         new(dlog);
  177.         dlog.IDoorEditDialog(mapList);
  178.         dlog.Show;
  179.     end;
  180.  
  181. end.